package com.pinc.exam;

import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class Missed_List extends WidgetActivity {
	private ListView lv;
	private DBClass dbHelper;
	private Cursor mCursor;
	private Question_Adapter mAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list_layout);

		dbHelper = new DBClass(this);
		mAdapter = new Question_Adapter(this);

		mCursor = dbHelper.getQuestionsInMissedList();

		if (mCursor.moveToFirst())
		{
			do{
				Question_Class qc = new Question_Class(
						mCursor.getInt(mCursor.getColumnIndex("_id")),
						mCursor.getInt(mCursor.getColumnIndex("_id")),
						mCursor.getString(mCursor.getColumnIndex(DBClass.COL_QLIB_QUESTION)),
						mCursor.getInt(mCursor.getColumnIndex(DBClass.COL_QLIB_BINGO_NO)),
						mCursor.getInt(mCursor.getColumnIndex(DBClass.COL_QLIB_TESTED_NO)),
						mCursor.getFloat(mCursor.getColumnIndex(DBClass.COL_QLIB_CREDIT))
				);
				mAdapter.add(qc);
			}while(mCursor.moveToNext());
		}
		mCursor.close();
		dbHelper.mDB.close();

		initWidget();

		lv.setAdapter(mAdapter);
		lv.setOnItemClickListener(ViewListener);
	}

	private OnItemClickListener ViewListener = new OnItemClickListener() {
		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position,	long id) {
			if ( position <= mAdapter.getCount())
			{
				Intent intent = new Intent(Missed_List.this, Question_Content.class);
				intent.putExtra("ids", mAdapter.getIdArray());
				intent.putExtra("title", getResources().getString(R.string.str_errlist));
				intent.putExtra("pos", position);
				startActivity(intent);
			}
		}
	};

	@Override
	protected void initWidget() {
		super.initWidget();

		lv = (ListView) this.findViewById(R.id.listView1);

		/* set upbar */
		b_prev.setVisibility(View.VISIBLE);
		b_prev.setText(getResources().getString(R.string.str_back));
		b_prev.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		tv_title.setText(getResources().getString(R.string.str_errlist));

	}
}
